//
//  BaseTabbarViewController.m
//  XJMCustomer
//
//  Created by 高波 on 2018/12/25.
//  Copyright © 2018 Mr.hu. All rights reserved.
//

#import "BaseTabbarViewController.h"
#import "OrderListVC.h"
#import "HomeOrderTechnician.h"
#import "MineVC.h"
@interface BaseTabbarViewController ()<UITabBarControllerDelegate>
{
    HomeOrderTechnician *_home;
    MineVC *_mine;
}

@end

@implementation BaseTabbarViewController

- (instancetype)init
{
    self = [super init];
    if (self) {
        //未选中字体颜色
        [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:Tabbar_TitleColor,NSFontAttributeName:[UIFont systemFontOfSize:10]} forState:UIControlStateNormal];
        
        //选中字体颜色
        [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:Tabbar_TitleColor_selected,NSFontAttributeName:[UIFont systemFontOfSize:10]} forState:UIControlStateSelected];
        
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self addChildViewControllers];
}

- (void)addChildViewControllers
{
    _home = [[HomeOrderTechnician alloc] init];
    
    _mine = [[MineVC alloc] init];
    
    self.viewControllers = @[_home, _mine];
    
    self.tabBarItem.title = _home.tabBarItem.title;
    self.navigationItem.title  = _home.navigationItem.title;
    self.navigationItem.titleView = _home.navigationItem.titleView;
    self.navigationItem.rightBarButtonItem = _home.navigationItem.rightBarButtonItem;
    self.navigationItem.leftBarButtonItem = _home.navigationItem.leftBarButtonItem;
}

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
    [[NSUserDefaults standardUserDefaults] setObject:@(0) forKey:ktabbarChangeValue];
    [self performSelector:@selector(changeTabbarValue) withObject:nil afterDelay:0.1];
    if ([item.title isEqualToString:@"订单"]) {
        self.navigationItem.titleView = _home.navigationItem.titleView;
        self.navigationItem.title = _home.navigationItem.title;
        self.navigationItem.leftBarButtonItem = _home.navigationItem.leftBarButtonItem;
        self.navigationItem.rightBarButtonItem = _home.navigationItem.rightBarButtonItem;
    }else{
        self.navigationItem.titleView = _mine.navigationItem.titleView;
        self.navigationItem.title = _mine.navigationItem.title;
        self.navigationItem.rightBarButtonItem = _mine.navigationItem.rightBarButtonItem;
        self.navigationItem.leftBarButtonItem = _mine.navigationItem.leftBarButtonItem;
    }
}

- (void)changeTabbarValue
{
    [[NSUserDefaults standardUserDefaults] setObject:@(1) forKey:ktabbarChangeValue];
}

@end
